// V-backend/src/models/ProductImage.js
module.exports = (sequelize, DataTypes) => {
  const ProductImage = sequelize.define('ProductImage', {
    image_id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'image_id'
    },
    product_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      field: 'product_id'
    },
    image_url: {
      type: DataTypes.STRING(500),
      allowNull: false,
      field: 'image_url'
    },
    sort_order: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      field: 'sort_order'
    },
    created_at: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      field: 'created_at'
    }
  }, {
    tableName: 'v_product_image',
    timestamps: false
  });

  ProductImage.associate = function(models) {
    ProductImage.belongsTo(models.Product, {
      foreignKey: 'product_id',
      as: 'product'
    });
  };

  return ProductImage;
};